package com.anyview.service.impl;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.anyview.po.CompanyGoods;

import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.function.Consumer;

@Component
public class ExcelDataListener extends AnalysisEventListener<CompanyGoods> {

    private final List<CompanyGoods> dataList = new ArrayList<>();
    private final Consumer<List<CompanyGoods>> consumer;

    /**
     * 构造方法
     *
     * @param consumer 集合
     */
    public ExcelDataListener( Consumer<List<CompanyGoods>> consumer) {
        this.consumer = consumer;
    }

    @Override
    public void invoke(CompanyGoods data, AnalysisContext context) {
        dataList.add(data);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {
        consumer.accept(dataList);
    }
}
